file(GLOB_RECURSE _DISTRIBUTED_SRC_FILES RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} "*.cc")

if(NOT ENABLE_CPU OR WIN32 OR APPLE)
    list(REMOVE_ITEM _DISTRIBUTED_SRC_FILES "cluster/cluster_context.cc")
    list(REMOVE_ITEM _DISTRIBUTED_SRC_FILES "cluster/actor_route_table_proxy.cc")
else()
    list(REMOVE_ITEM _DISTRIBUTED_SRC_FILES "cluster/dummy_cluster_context.cc")
endif()

if(NOT ENABLE_CPU OR WIN32 OR APPLE)
    set(EXCLUDE_DIRS "rpc/" "cluster/topology/")
    foreach(EXCLUDE_DIR ${EXCLUDE_DIRS})
        foreach(EXCLUDE_FILE ${_DISTRIBUTED_SRC_FILES})
            string(FIND ${EXCLUDE_FILE} ${EXCLUDE_DIR} FOUND)
            if(${FOUND} EQUAL 0)
                list(REMOVE_ITEM _DISTRIBUTED_SRC_FILES ${EXCLUDE_FILE})
            endif()
        endforeach()
    endforeach()
endif()

if(${ENABLE_RDMA} STREQUAL "ON")
    include_directories(/usr/include/umdk)
else()
    list(REMOVE_ITEM _DISTRIBUTED_SRC_FILES "rpc/rdma/rdma_client.cc")
    list(REMOVE_ITEM _DISTRIBUTED_SRC_FILES "rpc/rdma/rdma_server.cc")
endif()

set_property(SOURCE ${_DISTRIBUTED_SRC_FILES} PROPERTY COMPILE_DEFINITIONS
            SUBMODULE_ID=mindspore::SubModuleId::SM_DISTRIBUTED)
add_library(_mindspore_distributed_obj OBJECT ${_DISTRIBUTED_SRC_FILES})
